% Gemini theme
% https://github.com/anishathalye/gemini

% ====================
% Dependencies
% ====================

\RequirePackage{exscale}
\RequirePackage{ragged2e}
\RequirePackage{changepage}
\RequirePackage{fontspec}

% ====================
% Fonts
% ====================

\newfontfamily\Raleway[Ligatures=TeX]{Raleway}
\newfontfamily\Lato[Ligatures=TeX]{Lato}

\usefonttheme{professionalfonts}

\setsansfont{Lato}[
  UprightFont=*-Light,
  ItalicFont=*-LightItalic,
  BoldFont=*-Regular,
  BoldItalicFont=*-Italic
]

\setbeamerfont{headline}{family=\Raleway}
\setbeamerfont{headline title}{size=\Huge,series=\bfseries}
\setbeamerfont{headline author}{size=\Large}
\setbeamerfont{headline institute}{size=\normalsize}
\setbeamerfont{block title}{family=\Raleway,size=\large,series=\bfseries}
\setbeamerfont{heading}{family=\Lato,series=\bfseries}
\setbeamerfont{caption}{size=\small}
\setbeamerfont{footline}{family=\Raleway,size=\normalsize}

% ====================
% Macros
% ====================

\newcommand{\samelineand}{\qquad}

% ====================
% Elements
% ====================

% List
\makeatletter
\def\@listi{\leftmargin\leftmarginii
\topsep 1ex % spacing before
\parsep 0\p@ \@plus\p@
\itemsep 0.5ex} % spacing between
\makeatother

% Itemize

\setbeamertemplate{itemize item}{\raise0.5ex \hbox{\vrule width 0.5ex height 0.5ex}}
\setbeamertemplate{itemize subitem}{\raise0.3ex \hbox{\vrule width 0.5ex height 0.5ex}}
\setbeamertemplate{itemize subsubitem}{\raise0.2ex \hbox{\vrule width 0.5ex height 0.5ex}}

% Enumerate

\setbeamertemplate{enumerate item}{\insertenumlabel.}
\setbeamertemplate{enumerate subitem}{\insertsubenumlabel.}
\setbeamertemplate{enumerate subsubitem}{\insertsubsubenumlabel.}

% Equation
\setlength\belowdisplayshortskip{2ex}

% Caption
\setbeamertemplate{caption}[numbered]
\setbeamertemplate{caption label separator}[period]
\setlength{\abovecaptionskip}{2ex}
\setlength{\belowcaptionskip}{1ex}

% Bibliography
\setbeamertemplate{bibliography item}[text]

% Navigation
\beamertemplatenavigationsymbolsempty

% ====================
% Components
% ====================

% Heading
\newcommand\heading[1]
{%
  \par\bigskip
  {\usebeamerfont{heading}\usebeamercolor[fg]{heading}#1}\par\smallskip
}

% Headline
\setbeamertemplate{headline}
{
  \begin{beamercolorbox}{headline}
    \begin{columns}
      \begin{column}{\paperwidth}
        \usebeamerfont{headline}
        \vskip3ex
        \centering
        {\usebeamerfont{headline title}\usebeamercolor[fg]{headline title}\inserttitle\\[0.5ex]}
        {\usebeamerfont{headline author}\usebeamercolor[fg]{headline author}\insertauthor\\[1ex]}
        {\usebeamerfont{headline institute}\usebeamercolor[fg]{headline institute}\insertinstitute\\[1ex]}
      \end{column}
    \end{columns}
    \vspace{5ex}
    \ifbeamercolorempty[bg]{headline rule}{}{
      \begin{beamercolorbox}[wd=\paperwidth,colsep=0.5ex]{headline rule}\end{beamercolorbox}
    }
  \end{beamercolorbox}
}

% Block
\setbeamertemplate{block begin}
{
  \begin{beamercolorbox}[colsep*=0ex,dp=2ex,center]{block title}
    \vskip0pt
    \usebeamerfont{block title}\insertblocktitle
    \vskip-1.25ex
    \begin{beamercolorbox}[colsep=0.025ex]{block separator}\end{beamercolorbox}
  \end{beamercolorbox}
  {\parskip0pt\par}
  \usebeamerfont{block body}
  \vskip-0.5ex
  \begin{beamercolorbox}[colsep*=0ex]{block body}
  \justifying
  \setlength{\parskip}{1ex}
  \vskip-2ex
}
\setbeamertemplate{block end}
{
  \end{beamercolorbox}
  \vskip0pt
  \vspace*{2ex}
}

% Alert Block
\setbeamertemplate{block alerted begin}
{
  \begin{beamercolorbox}[colsep*=0ex,dp=2ex,center]{block alerted title}
    \vskip0pt
    \usebeamerfont{block title}\insertblocktitle
    \vskip-1.25ex
    \begin{beamercolorbox}[colsep=0.025ex]{block alerted separator}\end{beamercolorbox}
  \end{beamercolorbox}
  {\parskip0pt\par}
  \usebeamerfont{block body}
  \vskip-0.5ex
  \begin{beamercolorbox}[colsep*=0ex]{block alerted body}
  \justifying
  \begin{adjustwidth}{1ex}{1ex}
  \setlength{\parskip}{1ex}
  \vskip-2ex
}
\setbeamertemplate{block alerted end}
{
  \end{adjustwidth}
  \vskip1ex
  \end{beamercolorbox}
  \vskip0pt
  \vspace*{2ex}
}

% Footer
\newcommand{\footercontent}[1]{\newcommand{\insertfootercontent}{#1}}

\setbeamertemplate{footline}{
  \ifdefined\insertfootercontent
  \begin{beamercolorbox}[vmode]{headline}
    \ifbeamercolorempty[bg]{headline rule}{}{
      \begin{beamercolorbox}[wd=\paperwidth,colsep=0.25ex]{headline rule}\end{beamercolorbox}
    }
    \vspace{1.5ex}
    \hspace{\sepwidth}
    \usebeamerfont{footline}
    \centering
    \insertfootercontent
    \hspace{\sepwidth}
    \vspace{1.5ex}
  \end{beamercolorbox}
  \else\fi
}
